package org.southyin.controller;

import org.southyin.model.CommonsResp;
import org.southyin.model.User;
import org.southyin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

//@Controller
//@ResponseBody
@RestController
public class HelloController3 {
    @Autowired
    UserService userService;
    @GetMapping("/hello3")
    public User hello() {
        System.out.println(2);
        User user = new User();
        user.setEmail("1089999");
        user.setPassword("sdgfsgfdfdsg");
        return user;
    }
    @PostMapping("/hello4")
    public CommonsResp hello4(User user, HttpSession session){
        if (user.getEmail() == null || user.getEmail().trim().equals("")) {
            return CommonsResp.failed(400, "登陆邮箱或密码不能为空");
        }else{
            CommonsResp resp = userService.test(user);
            if (resp.getData() != null) {
                session.setAttribute("loginer",resp.getData());
            }
            return resp;
        }
    }
}
